package cn.yjr.vector;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import cn.yjr.vector.a.DaoMaster;
import cn.yjr.vector.a.DaoSession;
import cn.yjr.vector.a.DoctorDao;
import cn.yjr.vector.a.My_RegistrationDao;
import cn.yjr.vector.tools.BitmapHelper;
import cn.yjr.vector.tools.RegistrationInfo;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.LayoutParams;
import com.actionbarsherlock.app.SherlockActivity;

import org.json.JSONObject;

public class RegistrationInfoActivity extends SherlockActivity
  implements View.OnClickListener
{
  ActionBar actionBar;
  String captcha = "X23SDSA";
  TextView captcha_tv;
  Context context;
  private Cursor cursor;
  private DaoMaster daoMaster;
  private DaoSession daoSession;
  String date = "2014年4月9日 星期三";
  TextView date_tv;
  private SQLiteDatabase db;
  private DoctorDao doctorDao;
  ImageView doctor_head_imv;
  String doctor_info = "北医三院 神经科 主任";
  TextView doctor_info_tv;
  String doctor_name = "柳熠";
  TextView doctor_name_tv;
  DaoMaster.DevOpenHelper helper;
  LayoutInflater inflater;
  JSONObject jsonInfo;
  Handler mHandler;
  private My_RegistrationDao myRegistrationDao;
  long registration_id;
  String response;
  String time = "上午 10:00";
  TextView time_tv;
  View title_bar;

  private void initComponent()
  {
    this.doctor_name_tv = ((TextView)findViewById(R.id.doctor_name));
    this.doctor_info_tv = ((TextView)findViewById(R.id.doctor_info));
    this.date_tv = ((TextView)findViewById(R.id.add_date));
    this.time_tv = ((TextView)findViewById(R.id.add_time));
    this.captcha_tv = ((TextView)findViewById(R.id.captcha));
    this.doctor_head_imv = ((ImageView)findViewById(R.id.doctor_head));
    this.doctor_name_tv.setText(this.doctor_name);
    this.doctor_info_tv.setText(this.doctor_info);
    this.date_tv.setText(this.date);
    this.time_tv.setText(this.time);
    this.captcha_tv.setText(this.captcha);
    this.doctor_head_imv.setImageBitmap(BitmapHelper.toRoundBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.head)));
  }

  private void initData()
  {
    RegistrationInfo localRegistrationInfo = this.myRegistrationDao.load(registration_id).switchTo();
    this.doctor_name = localRegistrationInfo.getDoctorName();
    this.doctor_info = localRegistrationInfo.getDocDetail();
    this.date = localRegistrationInfo.getDate();
    this.time = localRegistrationInfo.getSmallTime();
    this.captcha = localRegistrationInfo.getCaptcha();
  }

  private void initDataBase()
  {
    this.helper = new DaoMaster.DevOpenHelper(this.context, "yijiaren-db", null);
    this.db = this.helper.getWritableDatabase();
    this.daoMaster = new DaoMaster(this.db);
    this.daoSession = this.daoMaster.newSession();
    this.myRegistrationDao = this.daoSession.getMy_RegistrationDao();
    this.doctorDao = this.daoSession.getDoctorDao();
  }

  private void initEventListener()
  {
  }

  private void initTitleBar()
  {
	ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,ActionBar.LayoutParams.WRAP_CONTENT,Gravity.CENTER);
    this.title_bar = this.inflater.inflate(R.layout.registration_info_action_bar, null);
    this.actionBar.setCustomView(this.title_bar, lp);
    this.actionBar.setDisplayShowHomeEnabled(false);
    this.actionBar.setDisplayShowTitleEnabled(false);
    this.actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    this.actionBar.setDisplayShowCustomEnabled(true);
  }

  public void onClick(View paramView)
  {
    paramView.getId();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(R.layout.activity_registration_info);
    this.inflater = getLayoutInflater();
    this.actionBar = getSupportActionBar();
    this.context = this;
    this.registration_id = getIntent().getLongExtra("registration_id", 1L);
    initTitleBar();
    initDataBase();
    initData();
    initComponent();
    initEventListener();
  }
}